package com.teamin.service;

import com.teamin.entity.CommentEntity;
import com.teamin.entity.TaskEntity;
import com.teamin.entity.TaskRemindEntity;
import com.teamin.entity.UserEntity;
import com.teamin.web.exception.GlobalErrorInfoException;
import com.teamin.web.model.TaskQueryModel;
import org.apache.ibatis.annotations.Param;

import java.io.UnsupportedEncodingException;
import java.util.*;

public interface TaskService {

	public static long DAY = 1000 * 60 * 60 * 24 ; //一天
	public static long HOUR = 1000 * 60 * 60 ; //一小时
	public static long MINUTE = 1000 * 60 ; //一分钟

	TaskRemindEntity updateTaskRemind(Long taskId, Date planFinishTime,TaskRemindEntity taskRemindEntity, Long controlUser) throws Exception;

    int deleteTaskRemind(Long taskId, Long controlUser) throws Exception;

    TaskRemindEntity getTaskRemind(Long taskId, Long controlUser) throws Exception;

    Boolean isdeleted(Long taskId);

	Boolean isSubTask(Long taskId);

	Long getParentTaskId(Long taskId);

    List<TaskEntity> selectJustCreateTask(Long circleId, Long userId,Long limit);

	Long selectLookJustCreateTaskCount(Long circleId, Long userId);

	int updateLookJustCreateTaskTime(Long circleId, Long userId,String userFlag);

	public enum TaskRemind {

		REMIND_TYPE_DAY(1, "day"), //按天计算
		REMIND_TYPE_HOUR(2, "hour"),//按小时计算
		REMIND_TYPE_MINUTE(3, "minute") ;//按分钟计算

		private final short type;

		private final String desc;

		TaskRemind(int value, String message) {
			this.type = (short) value;
			this.desc = message;
		}

		/**
		 * @param desc
		 * @return
		 */
		public static TaskRemind getTaskRemind(String desc) {

			TaskRemind[] li = TaskRemind.values();;
			for(TaskRemind rd :li) {
				if(desc.equals(rd.getMessage())) {
					return rd ;
				}
			}
			return null ;
		}

		/**
		 * Return the integer value of this status code.
		 */
		public short value() {
			return this.type;
		}
		public String getMessage() {
			return this.desc;
		}
	}


	 int deleteTaskById(Long id,Long controlUser,Long circleId,String userFlag) throws GlobalErrorInfoException;

	    /**
	     * 添加任务 ID 会返回到 TaskEntity 中的taskId 中
	     * taskName 任务名称
	     * description 任务描述
	     * planFinishTime 任务结束时间
	     * assignerId 任务执行者
	     * createrId (必) 任务创建者
	     * @param record
	     * @return
	     * @throws GlobalErrorInfoException 
	     */
	    long addTask(TaskEntity record) throws GlobalErrorInfoException;

	    /**
	     * 查询任务
	     * @param taskId (必) 任务ID
	     * @return TaskEntity
	     * @throws GlobalErrorInfoException 
	     */
	TaskEntity selectTaskById(Long taskId) ;

	TaskEntity selectTaskBase(Long taskId);

	List<TaskEntity> selectSubTask(Long parentTaskId);

    TaskEntity selectTaskV010AndCommentAndAttentionUser(Long taskId, Long userId, Long circleId) throws GlobalErrorInfoException;

    /**
	     * 删除任务
	     * taskId(必) 任务ID
	     * @return
	     * @throws GlobalErrorInfoException 
	     */
	    int setTaskStateDelete(Long taskId) throws GlobalErrorInfoException;


    Long selectCircleIdByTask(Long taskId, Long userId);

    /**
	     * 关联任务跟圈子
	     * taskId(必) 任务ID
	     * circleId(必) 圈子ID
	     * @return 0表示失败,1表示成功
	     * @throws GlobalErrorInfoException 
	     */
	    int addTaskToCircle(TaskEntity taskEntity,Long circleId,Long controlUser) throws GlobalErrorInfoException;

	    /**
	     * 查询圈子中的任务
	     * @param circleId 圈子ID(必)
	     * @param order 任务的 排序 11为创建时间倒序,21 为更新时间倒序
		 * @param filter 任务的过滤
	     */
	    public List<TaskEntity> selectByCircle(@Param("circleId") Long circleId, @Param("order")Integer order,@Param("filter")String filter) ;

	    /**
	     * 条件查询tasks
	     * @param taskQueryModel
	     * @return
	     */
	public List<TaskEntity> queryTasks(TaskQueryModel taskQueryModel) ;

    List<TaskEntity> selectByCircleV010(Long circleId, Integer order, String filter, List<String> labels,Long userId, int state,String assignerId);

    /**
	     * 关注任务
	     * @param taskId 任务ID(必)
	     * @param userId 用户ID(必)
	     * @throws GlobalErrorInfoException 
	     */
	public int addAttention(Long taskId,Long userId) throws GlobalErrorInfoException ;


	int updateAttentions(Long taskId, ArrayList<Long> userIds, Long controlUserId) throws GlobalErrorInfoException;

	/**
	     * 取消关注任务
	     * @param taskId 任务ID(必)
	     * @param userId 用户ID(必)
	     * @throws GlobalErrorInfoException 
	     */
	    public int removeAttention(Long taskId,Long userId,Long controlUserId) throws GlobalErrorInfoException ;

	    /**
	     * 获取任务的关注列表
	     * @param taskId 任务ID(必)
	     */
	    public List<UserEntity> getAttention(@Param("taskId") Long taskId) ;

    Set<Long> getAttentionUserId(Long taskId);

    /**
	     * 评论任务
	     * @param taskId 评论的任务(必)
	     * @param userId 评论的用户(必)
	     * @param contentType 评论的类型 1 为文本信息,2表图片(必)
	     * @param content 评论的内容(必)
	     * @return
	     * @throws GlobalErrorInfoException 
	     */
	    public int addComment(CommentEntity commentEntity) throws GlobalErrorInfoException ;

	    /**
	     * 任务评论列表
	     * @param taskId 评论的任务(必)
	     * @return
	     */
	    public List<CommentEntity> getComment(@Param("taskId") Long taskId) throws UnsupportedEncodingException;
	    
	    /**
	     * 更新任务
	     * taskId(必) 任务ID
	     * taskName 任务名称
	     * description 任务描述
	     * planFinishTime 任务结束时间
	     * assignerId 任务执行者
	     * createrId (必) 任务创建者
	     * @return
	     * @throws GlobalErrorInfoException 
	     */
		long updateTask(TaskEntity record, Long controlUserId,String planFinishTime) throws GlobalErrorInfoException;
		
		/**
		 * 需要作为消息通知的任务
		 * @param circleId
		 * @param userId
		 * @return
		 */
		Map<String, Object> getNeedNoticeTasks(Long circleId, Long userId);
		
		/**
	     * 查找一条评论
	     * @param taskId 评论的任务(必)
	     * @return
		 * @throws GlobalErrorInfoException 
	     */
	    public CommentEntity getCommentById(Long commentId) throws GlobalErrorInfoException ;

	int deleteCommentById(Long commentId) throws GlobalErrorInfoException;

	/**
	     * 删除一条评论
	     * @param taskId 评论的任务(必)
	     * @return
	     * @throws GlobalErrorInfoException 
	     */
	    public int deleteCommentById(CommentEntity commentEntity) throws GlobalErrorInfoException ;
	    
	    /**
	     * 用户是否拥有这个任务
	     * @param userId
	     * @param taskId
	     * @return
	     */
	    public boolean userHasTask(Long userId,Long taskId);

		int removeAllAttention(Long taskId,Long controlUserId);

	String getUserNameByTask(Long taskId, Long userId);

	int updateUserReadLastPosition(Long taskId, Long userId,String userFlag);

	/**
	 * 根据任务id，获取圈子id
	 * @param taskId
	 * @return
	 */
	Integer getCircleIdByTaskId(Integer taskId);
}
